import java.util.*;

/**
 * Created whit IntelliJ IDEA.
 * Description：
 * User：ZHONGCHEN
 * Date:2022-02-08
 * Time:21:09
 */
public class text {

        public static int[] gridIllumination1(int n, int[][] lamps, int[][] queries) {
            Map<Integer, Integer> row = new HashMap<Integer, Integer>();
            Map<Integer, Integer> col = new HashMap<Integer, Integer>();
            Map<Integer, Integer> diagonal = new HashMap<Integer, Integer>();
            Map<Integer, Integer> antiDiagonal = new HashMap<Integer, Integer>();
            Set<Long> points = new HashSet<Long>();
            for (int[] lamp : lamps) {
                if (!points.add(hash(lamp[0], lamp[1]))) {
                    continue;
                }
                row.put(lamp[0], row.getOrDefault(lamp[0], 0) + 1);
                col.put(lamp[1], col.getOrDefault(lamp[1], 0) + 1);
                diagonal.put(lamp[0] - lamp[1], diagonal.getOrDefault(lamp[0] - lamp[1], 0) + 1);
                antiDiagonal.put(lamp[0] + lamp[1], antiDiagonal.getOrDefault(lamp[0] + lamp[1], 0) + 1);
            }
            int[] ret = new int[queries.length];
            for (int i = 0; i < queries.length; i++) {
                int r = queries[i][0], c = queries[i][1];
                if (row.getOrDefault(r, 0) > 0) {
                    ret[i] = 1;
                } else if (col.getOrDefault(c, 0) > 0) {
                    ret[i] = 1;
                } else if (diagonal.getOrDefault(r - c, 0) > 0) {
                    ret[i] = 1;
                } else if (antiDiagonal.getOrDefault(r + c, 0) > 0) {
                    ret[i] = 1;
                }
                for (int x = r - 1; x <= r + 1; x++) {
                    for (int y = c - 1; y <= c + 1; y++) {
                        if (x < 0 || y < 0 || x >= n || y >= n) {
                            continue;
                        }
                        if (points.remove(hash(x, y))) {
                            row.put(x, row.get(x) - 1);
                            if (row.get(x) == 0) {
                                row.remove(x);
                            }
                            col.put(y, col.get(y) - 1);
                            if (col.get(y) == 0) {
                                col.remove(y);
                            }
                            diagonal.put(x - y, diagonal.get(x - y) - 1);
                            if (diagonal.get(x - y) == 0) {
                                diagonal.remove(x - y);
                            }
                            antiDiagonal.put(x + y, antiDiagonal.get(x + y) - 1);
                            if (antiDiagonal.get(x + y) == 0) {
                                antiDiagonal.remove(x + y);
                            }
                        }
                    }
                }
            }
            return ret;
        }

        public static long hash(int x, int y) {
            return (long) x + ((long) y << 32);
        }
    public static void main(String[] args) {
        int[][] num = {{0,0},{4,4}};
        int[][] p = {{1,1},{1,1}};
        text t =new text();
        System.out.println(Arrays.toString(text.gridIllumination1(5, num, p)));
    }
}
